<?php
/**
 * Created by PhpStorm.
 * User: yangwang
 * Date: 2024-04-17
 * Time: 14:22
 */

namespace App\Kuafu\Shop\Model;


use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\User\Model\User;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
 * App\Kuafu\Shop\Model\ShopStaffRecordLogModel
 *
 * @property int $id
 * @property int $shopId 门店ID
 * @property int $shopCode 门店Code
 * @property int $userId 用户ID
 * @property int $operateType 操作类型:0-系统,1-内部,2-后台,3-商家
 * @property int $actionType 行为类型,具体见model的actionTypeMap
 * @property string $remark 备注
 * @property int $createdByUid 创建人
 * @property int $updatedByUid 更新人
 * @property int $createdAt 创建时间
 * @property int $updatedAt 更新时间
 */
class ShopStaffRecordLogModel extends BaseModel
{
    protected $connection = 'mysql';
    protected $table      = 'shop_staff_records_log';


    /**
     * operateType
     */
    const OPERATE_TYPE_SYS      = 0;
    const OPERATE_TYPE_INNER    = 1;
    const OPERATE_TYPE_BACK     = 2;
    const OPERATE_TYPE_MERCHANT = 3;

    const OPERATE_TYPE_MAP = [
        self::OPERATE_TYPE_SYS      => '系统',
        self::OPERATE_TYPE_INNER    => '内部',
        self::OPERATE_TYPE_BACK     => '后台',
        self::OPERATE_TYPE_MERCHANT => '商家',
    ];

    /**
     * action_type
     */
    const ACTION_TYPE_CARD_EXPIRED          = 0;
    const ACTION_TYPE_CARD_CHANGE_DATE      = 1;
    const ACTION_TYPE_AUDIT_APPROVED        = 3;
    const ACTION_TYPE_AUDIT_REJECT          = 4;
    const ACTION_TYPE_ADD_STAFF             = 5;
    const ACTION_TYPE_CHANGE_STAFF          = 6;
    const ACTION_TYPE_JOIN_ENTERPRISE       = 7;
    const ACTION_TYPE_LEAVE_ENTERPRISE      = 8;
    const ACTION_TYPE_JOIN_ENTERPRISE_AGAIN = 9;
    const ACTION_TYPE_CHANGE_INFO           = 10;

    const ACTION_TYPE_MAP = [
        self::ACTION_TYPE_CARD_EXPIRED          => '证件过期',
        self::ACTION_TYPE_CARD_CHANGE_DATE      => '修改发证日期',
        self::ACTION_TYPE_AUDIT_APPROVED        => '审核通过',
        self::ACTION_TYPE_AUDIT_REJECT          => '审核驳回',
        self::ACTION_TYPE_ADD_STAFF             => '新建员工',
        self::ACTION_TYPE_CHANGE_STAFF          => '修改员工',
        self::ACTION_TYPE_JOIN_ENTERPRISE       => '员工入职',
        self::ACTION_TYPE_LEAVE_ENTERPRISE      => '员工离职',
        self::ACTION_TYPE_JOIN_ENTERPRISE_AGAIN => '员工再入职',
        self::ACTION_TYPE_CHANGE_INFO           => '修改信息',//商家app上修改员工信息
    ];

    /**
     * @return HasOne
     */
    public function createdUserRel(): HasOne
    {
        return $this->hasOne(User::class, 'id', 'createdByUid')->select([
            'id',
            'username'
        ]);
    }

}